package Summative;

import java.util.*;
import javax.swing.*;

public class MenuItemList
{   
  ArrayList <JMenuItem> list;
  VectorList vectors;
  JTextField field;
  Menu menu;
  int counter = 1;
  
  public MenuItemList(Menu menu)
  {
    list = new ArrayList <JMenuItem> ();
    this.menu = menu;
  }
  
  public void setTextField(JTextField field)
  {
    this.field = field;
  }
  
  public void setVectorList(VectorList vectors)
  {
    this.vectors = vectors;
  }
  
  public void addJMenuItem()
  {
    JMenuItem item = new JMenuItem(String.valueOf(counter));
    list.add(item);
    MenuVectorListener listener = new MenuVectorListener(item, vectors, field);
    item.addActionListener(listener);
    addItems();
    counter++;
  }
  
  public ArrayList <JMenuItem> getArray()
  {
    return list;
  } 
  
  public void addItems()
  {
    for(JMenuItem item: this.getArray())
    { 
      menu.addItem(item);
    } 
  }
  
}